package com.example.mongodbstudy.config;

import com.example.mongodbstudy.mongo.Main;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

/**
 * Spring Boot 整合MongoDB
 *
 * @author by Mr. Li 2021/4/20 18:14
 */
@Configuration
public class AppConfig {

    @Bean
    public MongoClient mongoClient() {
        return MongoClients.create(Main.MONGO_ADRESS);
    }

    @Bean
    public MongoTemplate mongoTemplate() {
        return new MongoTemplate(mongoClient(), "springBoot_productDB");
    }

}
